<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * @var $this \Magento\Downloadable\Block\Customer\Products\ListProducts
 */
?>
<?php $_items = $this->getItems(); ?>
<?php if(count($_items)): ?>
    <div class="table-wrapper downloadable-products">
        <table id="my-downloadable-products-table" class="data table table-downloadable-products">
            <caption class="table caption"><?php echo __('Downloadable Products') ?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?php echo __('Order #') ?></th>
                    <th scope="col" class="col date"><?php echo __('Date') ?></th>
                    <th scope="col" class="col title"><?php echo __('Title') ?></th>
                    <th scope="col" class="col status"><?php echo __('Status') ?></th>
                    <th scope="col" class="col remaining"><?php echo __('Remaining Downloads') ?></th>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($_items as $_item): ?>
                <tr>
                    <td data-th="<?php echo $this->escapeHtml(__('Order #')) ?>" class="col id">
                        <a href="<?php echo $this->getOrderViewUrl($_item->getPurchased()->getOrderId()) ?>" 
                            title="<?php echo $this->escapeHtml(__('View Order')) ?>">
                            <?php echo $_item->getPurchased()->getOrderIncrementId() ?>
                        </a>
                    </td>
                    <td data-th="<?php echo $this->escapeHtml(__('Date')) ?>" class="col date"><?php echo $this->formatDate($_item->getPurchased()->getCreatedAt()) ?></td>
                    <td data-th="<?php echo $this->escapeHtml(__('Title')) ?>" class="col title">
                        <strong class="product-name"><?php echo $this->escapeHtml($_item->getPurchased()->getProductName()) ?></strong>
                        <a href="<?php echo $this->getDownloadUrl($_item) ?>" title="<?php echo $this->escapeHtml(__('Start Download')) ?>" class="action download" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo $this->escapeHtml($_item->getLinkTitle()) ?></a>
                    </td>
                    <td data-th="<?php echo $this->escapeHtml(__('Status')) ?>" class="col status"><?php echo __(ucfirst($_item->getStatus())) ?></td>
                    <td data-th="<?php echo $this->escapeHtml(__('Remaining Downloads')) ?>" class="col remaining"><?php echo $this->getRemainingDownloads($_item) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($this->getChildHtml('pager')): ?>
        <div class="toolbar downloadable-products-toolbar bottom">
            <?php echo $this->getChildHtml('pager'); ?>
        </div>
    <?php endif; ?>
<?php else: ?>
    <div class="message info empty"><span><?php echo __('You have not purchased any downloadable products yet.'); ?></span></div>
<?php endif; ?>

<div class="actions-toolbar">
    <div class="secondary">
        <a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>" class="action back">
            <span><?php echo __('Back') ?></span>
        </a>
    </div>
</div>
